package f.f0.f;

import f.d;
import f.d0;
import f.f0.c;
import f.m;
import f.r;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.ProxySelector;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* compiled from: RouteSelector */
public final class f {
    public final f.a a;
    public final d b;
    public final d c;
    public final m d;
    public List<Proxy> e = Collections.emptyList();
    public int f;
    public List<InetSocketAddress> g = Collections.emptyList();
    public final List<d0> h = new ArrayList();

    /* compiled from: RouteSelector */
    public static final class a {
        public final List<d0> a;
        public int b = 0;

        public a(List<d0> list) {
            this.a = list;
        }

        public boolean a() {
            return this.b < this.a.size();
        }
    }

    public f(f.a aVar, d dVar, d dVar2, m mVar) {
        this.a = aVar;
        this.b = dVar;
        this.c = dVar2;
        this.d = mVar;
        r rVar = aVar.a;
        Proxy proxy = aVar.h;
        if (proxy != null) {
            this.e = Collections.singletonList(proxy);
        } else {
            List select = aVar.g.select(rVar.q());
            if (select == null || select.isEmpty()) {
                select = c.q(Proxy.NO_PROXY);
            } else {
                select = c.p(select);
            }
            this.e = select;
        }
        this.f = 0;
    }

    public void a(d0 d0Var, IOException iOException) {
        if (d0Var.b.type() != Type.DIRECT) {
            f.a aVar = this.a;
            ProxySelector proxySelector = aVar.g;
            if (proxySelector != null) {
                proxySelector.connectFailed(aVar.a.q(), d0Var.b.address(), iOException);
            }
        }
        d dVar = this.b;
        synchronized (dVar) {
            dVar.a.add(d0Var);
        }
    }

    public boolean b() {
        return c() || !this.h.isEmpty();
    }

    public final boolean c() {
        return this.f < this.e.size();
    }
}
